home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 516 < prev    next >
Internet Message Format  |  1996-08-06  |  3KB

  1. Path: mail2news.demon.co.uk!wbriscoe.demon.co.uk
  2. From: walter briscoe <walter@wbriscoe.demon.co.uk>
  3. Newsgroups: comp.sys.hp.hpux,comp.std.c,comp.lang.c
  4. Subject: Re: struct init problem
  5. Date: Wed, 06 Mar 96 08:41:54 GMT
  6. Distribution: na
  7. Message-ID: <826101714snz@wbriscoe.demon.co.uk>
  8. References: <DnrAEx.HA@tpoint.net>
  9. Reply-To: walter@wbriscoe.demon.co.uk
  10. X-NNTP-Posting-Host: wbriscoe.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.30
  12. X-Mail2News-Path: wbriscoe.demon.co.uk
  13.  
  14. In article <DnrAEx.HA@tpoint.net> devil@tpoint.net "The Devil Himself" writes:
  15.  
  16. > I found that the attached code does not compile on HP's, but does compile on
  17. > UNIXware, etc. I'd like to hear any ideas beside my hacked solution.
  18. > I'm looking for a way to preserve using the struct = { .... } syntax.
  19. > Also, who you characterize this problem vs. ansi C.....
  20.  
  21. [snip]
  22.  
  23. >         int     ima_int = 0xdeadbeef ;
  24. >         {
  25. >                 struct test_me please = 
  26. >                 {
  27. >                         0xbeefdead ,
  28. >                         & ima_int 
  29. >                 } ;
  30. >         /*
  31. >          * NOTE: HP-UX foo A.09.05 A 9000/712
  32. >          * wont compile this & ima_int statement, unless I declare
  33. >          * BOTH ima_int AND please as "static". unfortunately, I want this
  34. >          * code to be reenterant.
  35. >          */
  36.  
  37. As an aside. ints > 16 bits are unportable. long portably meets your
  38. needs.
  39.  
  40. I regret that the code does not conform with ANSI/ISO 9899-1990.
  41.  
  42. > 6.5.7 Initialization
  43.  
  44. [snip]
  45.  
  46. > All the expressions in an initializer for an object that has static
  47. > storage duration or in an initializer list for an object that has
  48. > aggregate or union type shall be constant expressions.
  49. >
  50. > 6.4 Constant expressions
  51.  
  52. [snip]
  53.  
  54. Constraints
  55.  
  56. [snip]
  57.  
  58. > A constant expression can be evaluated during translation rather than
  59. > runtime, and accordingly may be used in any place that a constant may
  60. > be.
  61.  
  62. The address of ima_int is not known at translate time.  I would argue
  63. that any implementation which allows a source containing this code to be
  64. translated without producing a diagnostic is not conforming because:
  65.  
  66. > 5.1.1.3 Diagnostics
  67. >
  68. > A conforming implementation shall produce at least one diagnostic
  69. > message (identified in an implementation-defined manner) for every
  70. > translation unit that contains a violation of any syntax rule or
  71. > constraint, even if the behavior is also explicitly specified as
  72. > undefined or implementation- defined.  Diagnostic messages need not be
  73. > produced in other circumstances.
  74.  
  75. I regret that you are stuck with the hack if you want to produce
  76. portable code.
  77. -- 
  78. walter briscoe
  79.